import { defineStore } from 'pinia'
import { ref, computed } from 'vue'

// 定义 store
export const useCounterStore = defineStore(
  'counter',
  () => {
    // 定义 state
    const count = ref(0)
    const testStr = ref('111')

    // 定义 getters
    const double = computed(() => count.value * 2)

    // 定义 actions
    const increment = () => {
      count.value++
    }

    const decrement = () => {
      count.value--
    }

    // 记得 return
    return { count, double, testStr, increment, decrement }
  },
  {
    persist: true,
  }
)
